package com.semidata.rtd.core.http.server;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpContentCompressor;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.util.concurrent.GenericFutureListener;

import java.util.concurrent.atomic.AtomicLong;

public class HttpServiceInitializer extends ChannelInitializer<SocketChannel> {

	private HttpDispatcher dispatcher;

	public HttpServiceInitializer(HttpDispatcher dispatcher) {
		this.dispatcher = dispatcher;
	}

	@Override
	public void initChannel(final SocketChannel ch) throws Exception {

		ChannelPipeline p = ch.pipeline();

		p.addLast("decoder", new HttpRequestDecoder());
		// p.addLast("aggregator", new HttpObjectAggregator(1048576));
		p.addLast("encoder", new HttpResponseEncoder());
		p.addLast("deflater", new HttpContentCompressor());
		p.addLast("handler", new HttpRequestHandler(dispatcher));
	}
}